#include "MaterialLib.h"

using namespace std;

/// <summary> 
/// Constructor 
/// </summary>
CICore::MaterialLib::MaterialLib() {
    Add  (new Material ());     //Adds the default material 
}

/// <summary> 
/// Destructor 
/// </summary>
CICore::MaterialLib::~MaterialLib() {
    //TODO
    ////Deleting all materials
    //map<const char*, Material*>::iterator it = materials.begin();

    //while (it != materials.end()) {
    //    if (it->second->name != Material::DEFAULT_MATERIAL);
    //        delete (it->second);
    //    it++;
    //}
}








///<************************************************************************************************************>
///<**************************************** region Utility Methods ********************************************>
///<************************************************************************************************************>

/// <summary>
/// Method called to add a material in the library
/// </summary>
/// <param name="m"> The material to be added </param>
/// <returns> A bool to indicate if the the material has been added </returns>
bool CICore::MaterialLib::Add (CICore::Material *m) {
    if (materials[m->name.c_str()] != 0)    //If already exists a material with the same name
        return false;                       //must return false

    materials[m->name.c_str()] = m;         //Adds the new material         
    return true;
}

/// <summary>
/// Method called to get a material from the library
/// </summary>
/// <param name="matName"> The material name </param>
/// <returns> The material identified by matName </returns>
CICore::Material* CICore::MaterialLib::Get (const char* matName) {
    return materials[matName];
}

/// <summary>
/// Method called to remove a material from the library
/// </summary>
/// <param name="matName"> The material name </param>
void CICore::MaterialLib::Remove (const char* matName) {
    materials.erase (matName);
}
/***************************************************************************************************************
******************************************* endregion Utility Methods ******************************************
****************************************************************************************************************/

